package com.xps.limedriver.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.xps.limedriver.R;
import com.xps.limedriver.utils.CommonUtils;
import com.xps.limedriver.view.base.BaseActivity;
import com.xps.limedriver.view.fragment.OrderFragment;
import com.zhy.autolayout.AutoLinearLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 吾丶说谎者 on 2017/11/21.
 */

public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
    View HeaderView;
    DrawerLayout drawer;
    @Bind(R.id.actionbar_iv_back)
    ImageView actionbarIvBack;
    @Bind(R.id.actionbar_tv_title)
    TextView actionbarTvTitle;
    @Bind(R.id.iv_msg)
    ImageView ivMsg;
    @Bind(R.id.Layout_Order)
    FrameLayout LayoutOrder;
    OrderFragment orderFragment;

    @Override
    protected int getLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void setData() {
        actionbarIvBack.setImageResource(R.mipmap.image_me);
        actionbarTvTitle.setText("青柠");
    }

    @Override
    protected void init(Bundle inBundle) {
        ButterKnife.bind(this);
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        HeaderView = navigationView.inflateHeaderView(R.layout.nav_header_main);
        AutoLinearLayout Layout_Me = (AutoLinearLayout) HeaderView.findViewById(R.id.Layout_Me);
        AutoLinearLayout Layout_Update= (AutoLinearLayout) HeaderView.findViewById(R.id.Layout_Update);
        Layout_Me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, MeActivity.class));
            }
        });
        Layout_Update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, UpdateActivity.class));
            }
        });
        orderFragment = new OrderFragment();
        CommonUtils.replaceFragment(R.id.Layout_Order, orderFragment, getSupportFragmentManager());
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        return false;
    }

    @OnClick({R.id.actionbar_iv_back, R.id.iv_msg})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.actionbar_iv_back:
                drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                drawer.openDrawer(GravityCompat.START);
                break;
            case R.id.iv_msg:
                break;
        }
    }
}